﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Acms.Bll;

public partial class Templates_Generic_TestamonialsModule : BaseUserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    public event EventHandler DataRequired;
    public List<Post> DataSource { get; set; }
    
    protected void dsTestamonials_SelectData(object sender, Acms.DataControls.SelectEventArgs<Acms.Bll.Post> e)
    {
        if (DataRequired != null)
        {
            DataRequired(this, EventArgs.Empty);
        }
        if (this.DataSource != null)
        {
            List<Post> posts = new List<Post>();
            Random rnd = new Random();
            while (DataSource.Count > 0 && posts.Count < 20)
            {
                int i = rnd.Next(0, DataSource.Count);
                posts.Add(DataSource[i]);
                DataSource.Remove(posts[posts.Count - 1]);
            }
            e.SetData(posts);
            this.DataSource = posts;
        }
    }

    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);
        if (list.Items.Count > 1)
        {
            Page.ClientScript.RegisterClientScriptInclude("jQuery", Page.ResolveUrl("~/js/jquery-1.2.6.min.js"));
            Page.ClientScript.RegisterClientScriptInclude("jCarouselLite", Page.ResolveUrl("~/js/jcarousellite_1.0.1.pack.js"));
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), this.ClientID, "jQuery(document).ready(function() {jQuery('.testamonials').jCarouselLite({ visible: 1, auto: 6500, speed: 250, vertical: false, start : 1, scroll : 1 });});", true);
        }
    }
}
